/*
 * @Author: huanggang
 * @Date: 2021-11-19 22:51:16
 * @LastEditors: huanggang
 * @LastEditTime: 2021-11-24 23:33:26
 * @Description: 
 */
#ifndef __UTIL_UDP_H__
#define __UTIL_UDP_H__

#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <stdio.h>
#include <unistd.h>
#include <string.h>
#include <sys/select.h>
#include <stdio.h>  
#include <stdlib.h>  
#include <string.h>  
#include <unistd.h>  
#include <arpa/inet.h>  
#include <sys/types.h>  
#include <sys/socket.h>  
#include <netinet/in.h>  
#include <net/if.h>  
#include <sys/types.h>
#include <sys/socket.h>
#include <stdio.h>
#include <linux/if.h>
#include <linux/if_ether.h>
#include <sys/ioctl.h>
#include <netinet/in.h>
#include <arpa/inet.h>

typedef struct _udp_info
{
    int fd;
    char *intf;
    struct sockaddr_in dst;
    struct sockaddr_in peer;
} UDP_INFO_T;

int udp_init(UDP_INFO_T *udp, char *interface, int local_port);
int udp_set_dst(UDP_INFO_T *udp, char *dst_ip, int dst_port);
int udp_enable_multicast(UDP_INFO_T *udp, char *multi_ip);
int udp_enable_broadcast(UDP_INFO_T *udp);
int udp_send2dst(UDP_INFO_T *udp, void *buf, int len);
int udp_send2peer(UDP_INFO_T *udp, void *buf, int len);
int udp_sendto(UDP_INFO_T *udp, void *buf, int len, char *dst_ip, int dst_port);
int udp_recv(UDP_INFO_T *udp, void *buf, int len, int ms);

#endif /* __UTIL_UDP_H__ */
